package app.maker.service;

import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import app.maker.entity.User;
import app.maker.error.UserException;
import app.maker.metier.entite.Authentification;
import app.maker.metier.userIntf.IGestionUser;

public class UserService {
	private Context context;

	private IGestionUser gUser;

	public UserService() {
		super();
		try {
			context = new InitialContext();
			gUser = (IGestionUser) context.lookup("gestionUser");
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}

	public Authentification connect(Authentification authentification)
			throws UserException {
		return gUser.connect(authentification);
	}

	public List<User> listAll() {
		return gUser.listAll();
	}

	public List<User> listUserActif() {
		return gUser.listUserActif();
	}

	public List<User> listUserBlock() {
		return gUser.listUserBlock();
	}
	
	public User getUser(int id) throws UserException {
		return gUser.consulterUser(id);
	}

	public Boolean add(User user) throws UserException {
		gUser.creerUser(user);
		return true;
	}
	
	public Boolean update(User user) throws UserException {
		gUser.updateUserDetails(user);
		return true;
	}

	public Boolean delete(User user) throws UserException {
		gUser.supprimerUser(user);
		return true;
	}

}
